(function () {
const STORAGE_KEY = 'asch-cookie-consent';
function getStoredChoice() {
try {
return window.localStorage.getItem(STORAGE_KEY);
} catch (error) {
return null;
}
}
function setStoredChoice(choice) {
try {
window.localStorage.setItem(STORAGE_KEY, choice);
} catch (error) {
// Ignore storage failures in private mode or restricted environments.
}
document.documentElement.dataset.cookieConsent = choice;
document.documentElement.dataset.optionalCookies = choice === 'accepted' ? 'allowed' : 'blocked';
}
function buildBanner() {
if (document.querySelector('[data-cookie-banner]')) {
return document.querySelector('[data-cookie-banner]');
}
const banner = document.createElement('aside');
banner.className = 'cookie-banner';
banner.dataset.cookieBanner = 'true';
banner.setAttribute('role', 'dialog');
banner.setAttribute('aria-live', 'polite');
banner.innerHTML = `
Cookie preferences
Optional cookies stay blocked until you choose otherwise.
We use essential cookies only for the site to function. Any optional cookies remain off unless you allow them.
You can change this later from the Cookie Policy page or the footer settings link.
`;
document.body.appendChild(banner);
return banner;
}
function openBanner() {
const banner = buildBanner();
banner.classList.add('is-visible');
banner.setAttribute('aria-hidden', 'false');
}
function closeBanner() {
const banner = document.querySelector('[data-cookie-banner]');
if (!banner) {
return;
}
banner.classList.remove('is-visible');
banner.setAttribute('aria-hidden', 'true');
}
function applyChoice(choice) {
setStoredChoice(choice === 'accept' ? 'accepted' : 'rejected');
closeBanner();
}
function init() {
const storedChoice = getStoredChoice();
if (storedChoice === 'accepted' || storedChoice === 'rejected') {
setStoredChoice(storedChoice);
} else {
document.documentElement.dataset.cookieConsent = 'pending';
document.documentElement.dataset.optionalCookies = 'blocked';
requestAnimationFrame(() => {
openBanner();
});
}
document.addEventListener('click', (event) => {
const settingsLink = event.target.closest('[data-cookie-settings]');
if (settingsLink) {
event.preventDefault();
openBanner();
return;
}
const choiceButton = event.target.closest('[data-cookie-choice]');
if (!choiceButton) {
return;
}
const choice = choiceButton.dataset.cookieChoice;
if (choice === 'details') {
event.preventDefault();
window.location.href = 'cookie-policy.html#cookie-preferences';
return;
}
event.preventDefault();
applyChoice(choice);
});
window.aschCookieConsent = {
get choice() {
return getStoredChoice();
},
open: openBanner,
accept: () => applyChoice('accept'),
reject: () => applyChoice('reject')
};
}
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', init, { once: true });
} else {
init();
}
})();